package com.xinqi.modules.prepare.video.convert;

import com.xinqi.common.mapstruct.CommonConvertConfig;
import com.xinqi.modules.prepare.common.dto.data.PrepareVideoData;
import com.xinqi.modules.prepare.video.domain.PrepareVideoEntity;
import com.xinqi.modules.prepare.video.dto.req.PrepareVideoCreateDTO;
import com.xinqi.modules.prepare.video.dto.req.PrepareVideoUpdateDTO;
import com.xinqi.modules.prepare.video.dto.rsp.PrepareVideoResultDTO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;

/**
 * 备课区互动视频转换
 *
 * @author: system
 * @date: 2023/03/19
 */
@Mapper(config = CommonConvertConfig.class)
public abstract class PrepareVideoConvert {
    @Mapping(target = "files", expression = "java(com.xinqi.common.base.utils.json.JSON.stringify(s.getFiles()))")
    public abstract PrepareVideoEntity create(PrepareVideoCreateDTO s);

    public abstract PrepareVideoCreateDTO create(PrepareVideoData s);

    @Mapping(target = "files", expression = "java(com.xinqi.common.base.utils.json.JSON.stringify(s.getFiles()))")
    public abstract PrepareVideoEntity update(PrepareVideoUpdateDTO s, @MappingTarget PrepareVideoEntity t);

    @Mapping(target = "files", expression = "java(com.xinqi.common.base.utils.json.JSON.stringify(s.getFiles()))")
    public abstract PrepareVideoEntity update(PrepareVideoUpdateDTO s);

    @Mapping(target = "files", expression = "java(com.xinqi.common.base.utils.json.JSON.parseList(s.getFiles(), com.xinqi.common.base.dto.CommonFileDTO.class))")
    public abstract PrepareVideoResultDTO convert(PrepareVideoEntity s);

    public abstract PrepareVideoData convert(PrepareVideoResultDTO s);

    @Mapping(target = "id", ignore = true)
    @Mapping(target = "prepareId", ignore = true)
    @Mapping(target = "createBy", ignore = true)
    @Mapping(target = "createTime", ignore = true)
    @Mapping(target = "updateBy", ignore = true)
    @Mapping(target = "updateTime", ignore = true)
    @Mapping(target = "deleteTime", ignore = true)
    @Mapping(target = "isDelete", ignore = true)
    public abstract PrepareVideoEntity copy(PrepareVideoEntity t, @MappingTarget PrepareVideoEntity s);
}
